import random
c = 5000
while True:
    b = random.randint(1, 100)
    print("本轮幸运数字是 {}".format(b))
    while c >= 500:
            a = int(input("请输入一个数字："))
            if a > b:
                c -= 500
                print("大了，金币剩余：{}".format(c))
            elif a < b:
                c -= 500
                print("小了，金币剩余：{}".format(c))
            elif a == b:
                c += 3000
                print("恭喜猜中！金币：{}".format(c))
                d = input("是否继续下一轮游戏？(y/n): ")
                if d == 'y':
                    print("开始新游戏")
                    break
                elif d=='n':
                    print("系统退出")
                    exit()
            else:
                    print("游戏结束，感谢参与！")
